<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="/resources/template/template.xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:st="http://java.sun.com/jsf/composite/store">


    <ui:define name="content">
        <h:form>
            <h:outputStylesheet library="css" name="pharmacyA4.css"/>
            <h:panelGroup rendered="#{!storeGoodsReturnController.printPreview}" styleClass="alignTop" >
                <p:panel>

                    <f:facet name="header" >      

                        <h:panelGrid columns="15"  >
                            <h:outputLabel value="Dealor : "/>
                            <p:autoComplete converter="deal" value="#{storeGoodsReturnController.returnBill.toInstitution}"  
                                            forceSelection="true"
                                            completeMethod="#{dealerController.completeDealor}"
                                            var="vt" itemLabel="#{vt.name}" itemValue="#{vt}" >                               
                            </p:autoComplete>
                                                          
                            <p:selectOneMenu   id="cmbPs" value="#{storeGoodsReturnController.returnBill.paymentMethod}">                                                                     
                                <f:selectItems value="#{enumController.paymentMethods}"/>
                                <p:ajax process="cmbPs" update="lblCardRef txtCardRef lblCheqRef txtCheqRef 
                                        bank lblSlipRef txtSlipRef slipBank" event="change" />
                            </p:selectOneMenu>
                            <h:outputLabel id="lblCardRef" value="Card Ref. No" style="display: #{storeGoodsReturnController.returnBill.paymentMethod ne 'Card' ? 'none' : 'block'} ; " />
                            <p:inputText autocomplete="off"  id="txtCardRef" value="#{storeGoodsReturnController.returnBill.creditCardRefNo}" style="display: #{storeGoodsReturnController.returnBill.paymentMethod ne 'Card' ? 'none' : 'block'} ; " />

                            <h:outputLabel id="lblCheqRef" value="Cheque No" style="display: #{storeGoodsReturnController.returnBill.paymentMethod ne 'Cheque' ? 'none' : 'block'} ; " />
                            <p:inputText autocomplete="off"  id="txtCheqRef" value="#{storeGoodsReturnController.returnBill.chequeRefNo}" style="display: #{storeGoodsReturnController.returnBill.paymentMethod ne 'Cheque' ? 'none' : 'block'} ; " />
                            <h:selectOneMenu id="bank" value="#{storeGoodsReturnController.returnBill.bank}" style="display: #{storeGoodsReturnController.returnBill.paymentMethod ne 'Cheque' ? 'none' : 'block'} ; ">
                                <f:selectItem itemLabel="Select Bank"/>
                                <f:selectItems value="#{institutionController.banks}" var="inst" itemLabel="#{inst.name}" itemValue="#{inst}"/>
                            </h:selectOneMenu>

                            <h:outputLabel id="lblSlipRef" value="Slip Memo" style="display: #{storeGoodsReturnController.returnBill.paymentMethod ne 'Slip' ? 'none' : 'block'} ; " />
                            <p:inputText autocomplete="off"  id="txtSlipRef" value="#{storeGoodsReturnController.returnBill.comments}" style="display: #{storeGoodsReturnController.returnBill.paymentMethod ne 'Slip' ? 'none' : 'block'} ; " />
                            <h:selectOneMenu id="slipBank" value="#{storeGoodsReturnController.returnBill.bank}" style="display: #{storeGoodsReturnController.returnBill.paymentMethod ne 'Slip' ? 'none' : 'block'} ; ">
                                <f:selectItem itemLabel="Select Bank"/>
                                <f:selectItems value="#{institutionController.banks}" var="inst" itemLabel="#{inst.name}" itemValue="#{inst}"/>
                            </h:selectOneMenu>

                            <p:commandButton  value="Return" action="#{storeGoodsReturnController.settle}" ajax="false"  style="width: 150px; padding: 1px;border: 1px solid ; margin: auto;">
                            </p:commandButton>
                            <p:outputLabel  value="Recievable Amount" /> 
                            <p:outputLabel id="total"  value="#{storeGoodsReturnController.returnBill.total}" style="float: right;">
                                <f:convertNumber pattern="#,##0.00" />
                            </p:outputLabel>
                        </h:panelGrid>
                    </f:facet>
                </p:panel>

                <p:dataTable var="ph" value="#{storeGoodsReturnController.billItems}"
                             scrollable="true" scrollHeight="250"
                             id="itemList" editable="true">  

                    <p:ajax event="rowEdit" listener="#{storeGoodsReturnController.onEdit(ph)}" 
                            update=":#{p:component('total')} :#{p:component('tab')}" />  
                    <p:ajax event="rowEditCancel" listener="#{storeGoodsReturnController.onEdit(ph)}" 
                            update=":#{p:component('total')} :#{p:component('tab')}" /> 


                    <f:facet name="header">  
                        Returning Item 
                    </f:facet>

                    <p:column style="width:10px!important;">  
                        <p:rowEditor />  
                    </p:column>

                    <p:column headerText="Item Name" style="width: 250px!important;"  > 
                        <h:outputText id="item" value="#{ph.item.name}" >                                   
                        </h:outputText>
                    </p:column>  

                    <p:column  headerText="Ballance Qty in Unit" style="width:25px!important;"> 
                        <h:outputText id="qty" value="#{ph.pharmaceuticalBillItem.qty}" />                   
                    </p:column>  

                    <p:column headerText="Purchase Rate" style="width:25px!important;"> 
                        <h:panelGroup id="purchase" >
                            <h:outputText  value="#{ph.pharmaceuticalBillItem.purchaseRate}"  >
                                <f:convertNumber pattern="#,##0.00" />
                            </h:outputText>
                            <h:outputText value="perPack" rendered="#{ph.item.class eq 'class com.divudi.entity.pharmacy.Ampp'}" />    
                        </h:panelGroup>
                    </p:column>                 


                    <p:column headerText="Bathch No" style="width:25px!important;">                       
                        <h:outputText value="#{ph.pharmaceuticalBillItem.stringValue}" />                        
                    </p:column>  

                    <p:column headerText="Date of Expirey" style="width:25px!important;">                     
                        <h:outputText value="#{ph.pharmaceuticalBillItem.doe}" /> 
                    </p:column>


                    <p:column headerText="Returning Qty in Unit" style="width:25px!important;">     
                        <p:cellEditor>  
                            <f:facet name="output">  
                                <h:outputLabel value="#{ph.tmpQty}" />

                            </f:facet>
                            <f:facet name="input">  
                                <p:inputText autocomplete="off" value="#{ph.tmpQty}" >
                                </p:inputText>
                            </f:facet>
                        </p:cellEditor>
                    </p:column>  

                </p:dataTable>  
                <p:spacer height="50"/>
                <st:history/>
            </h:panelGroup>

            <p:panel rendered="#{storeGoodsReturnController.printPreview}">
                <p:commandButton ajax="false" action="store_grn_list_for_return" value="GRN List"/>                    
                <p:commandButton value="Print" ajax="false" action="#" >
                    <p:printer target="gpBillPreview" ></p:printer>
                </p:commandButton>
                <p:panel   id="gpBillPreview"   >

                    <st:grnReturn bill="#{storeGoodsReturnController.returnBill}"/>

                </p:panel>
            </p:panel>

        </h:form>
    </ui:define>  

</ui:composition>
